package name.fowler.refactoring.simplestore.output;

import name.fowler.refactoring.simplestore.calculators.FrequentStrategy;
import name.fowler.refactoring.simplestore.calculators.FrequentStrategySelector;
import name.fowler.refactoring.simplestore.calculators.RentalCalculator;
import name.fowler.refactoring.simplestore.domain.Customer;
import name.fowler.refactoring.simplestore.domain.Rental;

public class HTMLReport extends AbstaractReport {

	public HTMLReport(FrequentStrategySelector frequentSelector) {
		super(frequentSelector);
	}

	public String getCustomerReport(Customer customer) {
		String result = "Rental record for " + customer.getName() + "\n";
		double totalAmount = 0;

		for (Rental rental : customer.getRentals()) {
			double currAmount = new RentalCalculator().calculatePriceForMovie(rental);
			totalAmount += currAmount;
			result += "\t" + rental.getMovie().getTitle() + "\t" + currAmount + "\n";
		}

		result += "Amount owed is " + totalAmount + "\n";

		FrequentStrategy frequentStrategy = frequentSelector.select(customer);
		int totalDiscountPoints = frequentStrategy.calculateDiscount(customer);
		result += "You earned " + totalDiscountPoints + " frequent renter points.";
		return result;
	}

}
